use super::*;


pub fn load_csv<P: AsRef<Path>>(file: P) -> Result<String, Error> {
    let lines = read(file)?;
    Ok(lines)
}

pub fn write_csv<P: AsRef<Path>>(buf: &str, file: P) -> Result<(), Error> {
    let mut f = File::create(file)?;
    f.write_all(buf.as_bytes())?;
    Ok(())
}

fn open<P: AsRef<Path>>(file: P) -> Result<File, Error> {
    let f = File::open(file)?;
    Ok(f)
}

fn read<P: AsRef<Path>>(file: P) -> Result<String, Error> {
    let mut buf = String::new();
    let mut f = open(file)?;

    f.read_to_string(&mut buf)?;
    if buf.is_empty() {
        return Err("input file missing.")?;
    }
    Ok(buf)
}